package com.kevin.chat.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.kevin.chat.entity.UserEntity;
import com.kevin.chat.framework.util.JSONUtil;
import com.kevin.chat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/*
 * 聊天相关业务控制器
 * @author Kevin
 * @date 2021/1/14 9:17
 *
 */
@Controller()
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private UserService userService;


    /**
     * 好友列表
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/friendList")
    public String friendList() {
        return "";
    }

    /**
     * 用户信息
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/user")
    public String user(HttpServletRequest request) {
        String loginName = request.getParameter("loginName");
        UserEntity user = userService.getUserByLoginName(loginName);
        try {
            return JSONUtil.writeValueAsString(user);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
